import { _decorator, Component, Node, Vec3, Quat, assetManager, Texture2D } from 'cc';
import { GameCore } from './Base/Class';
import { EventSystem } from './Base/EventSystem';
import { getClassName, NewClass, setClassName } from './Base/Global';
import { Singleton } from './Base/Singleton';
import { AssetInfo } from './Manager/ResourceLoad/base/AssetInfo';
import { UILayer } from './Manager/UI/base/IUILevel';
import { UIManager } from './Manager/UI/UIManager';
import { TestPanel } from './test/TestPanel';
import { TEST_A } from './TestClass1';
import { TEST_B } from './TestClass2';
const { ccclass, property } = _decorator;

export class Base extends GameCore.ClassBase{
    public Print(){
        console.log("Base class");
    }
}
setClassName(Base, "Base")

export class Test1 extends Base{
    public Print(){
        console.log("Print：： Test1 class");
    }

}
setClassName(Test1, "Test1")
console.log(getClassName(Test1))

export class Test2 extends Base {
    public Print(){
        console.log("Test2 class");
    }
}
setClassName(Test2, "Test2")


@ccclass('HelloWorld')
export class HelloWorld extends Component {
    addVal:number = 0;
    rotation:number = 0;
    isUp:boolean = false;
    isUp2:boolean = true;
    start() {
        // this.addVal = this.node.scale.x;
        this.isUp = true;
        console.log("__HelloWorld:start__" + typeof(Test2));
        //console.log("__HelloWorld:start__" + TypeDefine.getClassName(Test2));
        var obj = NewClass(Test2);
        console.log("__HelloWorld:start__" + obj.className);
        console.log(Test1 == Base)

        new TEST_A().Print();
        new TEST_B().Print();

        this.node.addComponent(EventSystem);

        console.log(Singleton);
        console.log(Singleton.Instance(UIManager));

        // assetManager.loadBundle("model", (err, bundle)=>{
        //     console.log(err);
        //     console.log(bundle);
        //     bundle.load<Texture2D>("helloWorld/grass/grass", (err, data)=>{
        //         console.log(data);
        //     })

        //     bundle.load<Texture2D>("helloWorld/seafloor", (err, data)=>{
        //         console.log(data);
        //     })
        // });
        Singleton.Instance(UIManager).OpenUI(TestPanel, {}, UILayer.eTopLayer);
    }

    update(deltaTime: number) {
        var step = deltaTime / 10;
        if(this.isUp)
        {
            this.addVal = this.addVal + step;
            
            if(this.addVal >= 3){
                this.addVal = 3;
                this.isUp = false;
            }
        }
        else{
            this.addVal = this.addVal - step;

            if(this.addVal <= 1){
                this.addVal = 1;
                this.isUp = true;
            }
        }

        this.node.setScale(new Vec3(this.addVal, this.addVal, this.addVal));

        if(this.isUp2)
        {
            this.rotation += deltaTime * 10;
            if(this.rotation >= 180){
                this.rotation = 180;
                this.isUp2 = false;
            }
        }
        else
        {
            this.rotation -= deltaTime * 10;
            if(this.rotation <= 0){
                this.rotation = 0;
                this.isUp2 = true;
            }
        }
        var angle = this.rotation - 90;
        this.node.setRotationFromEuler(new Vec3(0, angle, 0));
    }
}


